<template>

	<b-layout-index>
		<theme-color-bg type="c3">
			<navbar :fixed="true"></navbar>
			<view class="pd-top-10 oval header  mg-bottom-10">
				<!-- 	<image class="mg-top-10" mode="aspectFit" src="../../static/image/login.png"></image> -->
				<view class="text-center">
					<view style="width: 60px;height: 60px; margin: 0 auto;">
						<u-avatar :size="60" :src="userInfo.avatar"></u-avatar>
					</view>
					<view class="mg-top-10"><text class="font-size-18">{{userInfo.nickName}}</text></view>
				</view>

				<view class="text-center mg-top-10">

					<u-grid :border="false" col="2">
						<u-grid-item>
							<text class="font-size-14">{{userInfo.agent.name}} </text>
							<text class="font-size-10"> دەرىجىسى </text>
						</u-grid-item>
						<u-grid-item>
							<text class="font-size-14">{{userInfo.invite}}</text>
							<text class="font-size-10"> تەكلىپ كودى </text>
						</u-grid-item>
					</u-grid>

				</view>

			</view>
		</theme-color-bg>
		<view class="coverfill br-rd-top-30 ">
			<view class="pd-30">
				<view class="title   font-size-24  font-bold"> 基本信息 </view>
				<view>
					<u--form :borderBottom="false" :model="param" :rules="rules" ref="form1">
						<u-form-item prop="name">
							<view class="mg-top-10">
								<view class="input br-rd-6">
									<u-cell :border="false">
										<iconfont slot="icon" color="#3c9cff" icon="icon-wode" />

										<u--input slot="title" class="pd-left-10 pd-right-10" placeholder="请输入姓名"
											v-model="param.name" border="none"></u--input>
									</u-cell>
								</view>
							</view>
						</u-form-item>
						<u-form-item prop="nameUg">
							<view>
								<view class="input br-rd-6">
									<u-cell :border="false">
										<iconfont slot="icon" color="#3c9cff" icon="icon-wode" />
										<u--input slot="title" class="pd-left-10 pd-right-10" placeholder="请输入维语姓名"
											v-model="param.nameUg" border="none"></u--input>
									</u-cell>
								</view>
							</view>
						</u-form-item>
						<u-form-item prop="idcard">
							<view class="mg-top-10">
								<view class="input br-rd-6">
									<u-cell :border="false">
										<iconfont slot="icon" color="#3c9cff" icon="icon-shinshopgerenxinxi" />

										<u--input slot="title" class="pd-left-10 pd-right-10" placeholder="请输入身份证号"
											v-model="param.idcard" border="none"></u--input>
									</u-cell>
								</view>
							</view>
						</u-form-item>
						<u-form-item prop="phone">
							<view>
								<view class="input br-rd-6">
									<u-cell :border="false">
										<iconfont slot="icon" color="#3c9cff" icon="icon-shouji" />

										<u--input slot="title" class="pd-left-10 pd-right-10" placeholder="请输入手机号"
											v-model="param.phone" border="none"></u--input>
									</u-cell>
								</view>
							</view>
						</u-form-item>
						<u-form-item prop="wechat">
							<view>
								<view class="input br-rd-6">
									<u-cell :border="false">
										<iconfont slot="icon" color="#3c9cff" icon="icon-weixin1" />

										<u--input slot="title" class="pd-left-10 pd-right-10" placeholder="请输入微信号"
											v-model="param.wechat" border="none"></u--input>
									</u-cell>
								</view>
							</view>
						</u-form-item>




						<view class="mg-top-20">

							<u-button @click="goEdit()" customStyle="border-radius:6px" type="primary" :plain="true"
								text="提交">
							</u-button>

						</view>

					</u--form>


				</view>
			</view>


		</view>
	</b-layout-index>

</template>

<script>
	import {
		login,
		loginAccount,
		byPhone,
		byIdCard,
		regesterLogin
	} from '@/api/oauth.js'
	import {
		getAuthInfo,
		myEdit
	} from '@/api/user.js'

	export default {

		data() {
			var userInfo = uni.getStorageSync("userInfo")
			console.log(userInfo)
			return {
				userInfo: userInfo,
				authInfo: {
					id: 0
				},
				param: {
					idcard: "",
					name: "",
					nameUg: "",
					password: "",
					phone: "",
					repassword: "",
					wechat: ""

				},
				rules: {
					'name': [{
						type: 'string',
						required: true,
						message: '请填写姓名',
						trigger: ['blur', 'change']
					}, {
						pattern: /^[\u4e00-\u9fa5·]*$/g,
						// 正则检验前先将值转为字符串
						transform(value) {
							return String(value);
						},
						message: '姓名不正确',
						trigger: ['blur', 'change']
					}],
					"nameUg": [{
						required: true,
						message: '请输入维语姓名',
						trigger: ['blur'],
					}],

					// 字段名称
					"phone": [{
							required: true,
							message: '请输入手机号',
							trigger: ['blur'],
						},
						{
							// 自定义验证函数，见上说明
							validator: (rule, value, callback) => {
								// 上面有说，返回true表示校验通过，返回false表示不通过
								// uni.$u.test.mobile()就是返回true或者false的
								return uni.$u.test.mobile(value);
							},
							message: '手机号码不正确',
							// 触发器可以同时用blur和change
							trigger: ['blur'],
						}
						
					],
					// 字段名称
					"idcard": [{
							required: true,
							message: '请输入身份证号',
							trigger: ['blur'],
						},
						{
							// 自定义验证函数，见上说明
							validator: (rule, value, callback) => {
								// 上面有说，返回true表示校验通过，返回false表示不通过
								// uni.$u.test.mobile()就是返回true或者false的
								return uni.$u.test.idCard(value);
							},
							message: '身份证号不正确',
							// 触发器可以同时用blur和change
							trigger: ['blur'],
						}

					], // 字段名称
					"wechat": [{
						required: true,
						message: '请输入微信号',
						trigger: ['blur']
					}]

				},
			}
		},
		onLoad: function({
			type = 12,
			userId = 0
		}) {


			this.getAuthInfo()

		},
		onReady() {
			//onReady 为uni-app支持的生命周期之一
			this.$refs.form.setRules(this.rules)
		},
		methods: {
			getAuthInfo: function(userId = 0) {
				var the = this;
				getAuthInfo().then(res => {
					the.authInfo = res;
					the.param = res;
				})
			},
			goEdit: function(e) {
				var the = this
							var param = this.param;
				console.log("Login")
				//	this.$refs.form1.setRules(this.rules);
				let pages = getCurrentPages(); //获取所有页面栈实例列表
				let nowPage = pages[pages.length - 1]; //当前页页面实例
				let prevPage = pages[pages.length - 2]; //上一页页面实例
				//prevPage.$vm.detailList.receive = item; //修改上一页data里面的地址
				console.log("pages", nowPage, prevPage)
				this.$refs.form1.validate().then(res => {
					uni.$u.toast('校验通过')
					var a = myEdit(param)
					a.then(res => {
				

						uni.redirectTo({
							url: "/pages/index//user"
						})
					})


				}).catch(errors => {
					console.log(errors)
					uni.$u.toast('校验失败')
				})

			},
			loginSubmitAccond: function() {
				var the = this;
				var param = this.param;
				param['parentUserId'] = this.authInfo.id
				this.$refs.form1.validate().then(res => {
					uni.$u.toast('校验通过')
					console.log(param)

				}).catch(errors => {
					console.log(errors)
					uni.$u.toast('校验失败')
				})
			}
		}
	}

	var validatePass = (rule, value, callback) => {
		if (value === '') {
			callback(new Error('请输入密码'));
		} else {
			callback();
		}
	};
	var validatePass2 = (rule, value, callback) => {
		if (value === '') {
			callback(new Error('请再次输入密码'));
		} else if (value !== this.model2.password) {
			callback(new Error('两次输入密码不一致!'));
		} else {
			callback();
		}
	};
</script>

<style>
	.header {
		background-color: #7e9c52;
		height: 300px;
		color: #FFFFFF;
	}

	.tag {
		background-color: #FFFFFF !important;
		height: 100%;
	}

	page {
		background-color: #FFFFFF !important;
	}

	.coverfill {
		background-color: #FFFFFF;
		margin-top: -40px;
		min-height: 250px;
		z-index: 300;
		position: absolute;
		width: 100%;
		top: 270px;
		left: 0;
		height: 67%;
	}

	.br-rd-top-30 {
		border-top-left-radius: 30px;
		border-top-right-radius: 30px;
	}

	.title {
		color: #3c9cff;
	}

	.input {
		background-color: #3c9cff0f;
	}
</style>
